package by.dkusch.aircompany.model.tables;

import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.MapsId;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import by.dkusch.aircompany.model.tables.base.BaseEntity;

@Entity
public class UserProfile extends BaseEntity<Long> {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@MapsId
	@OneToOne(fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	@JoinColumn(updatable = false, name = "id")
	private UserAccount userAccount;

	@OneToMany(fetch = FetchType.LAZY, targetEntity = UserGrant.class, cascade = { CascadeType.ALL })
	@JoinColumn(name = "user_profile_id")
	private Set<UserGrant> userGrant;

	@NotNull
	@Size(max = 30)
	@Column
	private String code;

	@NotNull
	@Size(max = 50)
	@Column
	private String firstName;

	@NotNull
	@Size(max = 50)
	@Column
	private String secondName;

	@Size(max = 50)
	@Column
	private String lastName;

	@Column
	private Boolean dbaFl;

	public UserAccount getUserAccount() {
		return userAccount;
	}

	public void setUserAccount(UserAccount userAccount) {
		this.userAccount = userAccount;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getSecondName() {
		return secondName;
	}

	public void setSecondName(String secondName) {
		this.secondName = secondName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public Boolean getDbaFl() {
		if (dbaFl == null) {
			dbaFl = false;
		}
		return dbaFl;
	}

	public void setDbaFl(Boolean dbaFl) {
		this.dbaFl = dbaFl;
	}

	public Set<UserGrant> getUserGrant() {
		return userGrant;
	}

	public void setUserGrant(Set<UserGrant> userGrant) {
		this.userGrant = userGrant;
	}

}
